"""
@Author: CheyenneLam
@Date: 2020-11-15 11:00:00
@LastEditTime: 2020-11-15 11:00:00
@LastEditors: CheyenneLam
@Description: 根据起始日期获取日期list
@FilePath: \date_range.py
"""

from odps.udf import annotate
from datetime import datetime, timedelta
import time


@annotate("datetime,datetime->array<datetime>")
class DateRange(object):

    def evaluate(self, arg0, arg1):
        if None in (arg0, arg1):
            return None
        return date_range(arg0, arg1)


def date_range(begin_date, end_date):
    dates = []
    dt = datetime.strptime(begin_date, "%Y-%m-%d")
    d = begin_date[:]
    while d <= end_date:
        dates.append(d)
        dt = dt + timedelta(1)
        d = dt.strftime("%Y-%m-%d")
    return dates


if __name__ == '__main__':
    start_date = time.strptime('2020-02-01', '%Y-%m-%d')
    end_date = time.strptime('2021-02-10', '%Y-%m-%d')
    print(datetime.now())
    # for date in date_range(time.mktime(start_date), time.mktime(end_date)):
    #     print(date)
